import Taro from "@tarojs/taro";
import {View} from "@tarojs/components";
import currentEnv from "../../../configure/currentEnv";
import './index.scss'
import {getGlobalData} from "../../utils/globalData";

export default ({children,theme=0,pad=true})=>{
  const back=()=>{
    Taro.navigateBack().catch(() => {
      Taro.reLaunch({
        url:currentEnv.project=='yingjing'?'/pages/index/index':'/pages/movie/index'
      })
    });
  }
  const headerHeight=parseFloat(getGlobalData('headerHeight'))
  const statusBarHeight=parseFloat(getGlobalData('statusBarHeight'))
  return (
    <View className={`theme-${theme}`}>
      {
        !pad?'':
          <View className='header-pad' style={{height:`${statusBarHeight+headerHeight}px`}}></View>
      }
      <View className='custom-header'>
        <View className='status-bar' style={{height:`${statusBarHeight}px`}}></View>
        <View className='header-content' style={{height:`${headerHeight}px`}}>
          <View onClick={back} className='i-1'>
            <View className='at-icon at-icon-chevron-left'></View>
          </View>
          <View className='i-2 ellipsis'>{children}</View>
        </View>
      </View>
    </View>
  )
}
